package com.yuesystem.common;

import com.yuesystem.dto.UserSimple;

/**
 * 基于ThreadLocal封装的工具类，用于保存和获取用户当前的ID.
 */
public class BaseContext {
  private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
  private static ThreadLocal<UserSimple> userThreadLocal = new ThreadLocal<>();

  // 保存当前线程的ID到threadLocal中，工具类，用static方法
  public static void setCurrentId(Long id) {
    threadLocal.set(id);
  }

  // 获取当前线程的ID
  public static Long getCurrentId() {
    return threadLocal.get();
  }

  // 保存当前线程的user信息
  public static void setCurrentUser(UserSimple userSimple) {
    userThreadLocal.set(userSimple);
  }

  //获取当前线程的user信息
  public static UserSimple getCurrentUser() {
    return userThreadLocal.get();
  }
}

